/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package l2s.gameserver.scripts.quests;

import java.util.HashMap;

import l2s.commons.util.Rnd;
import l2s.gameserver.model.actor.L2Character;
import l2s.gameserver.model.actor.L2Npc;
import l2s.gameserver.model.actor.instance.L2PcInstance;
import l2s.gameserver.model.base.ClassId;
import l2s.gameserver.model.quest.Quest;
import l2s.gameserver.model.quest.QuestState;
import l2s.gameserver.scripting.ScriptFile;

public class Q230_TestOfSummoner extends Quest implements ScriptFile
{
	private static final String qn = "Q230_TestOfSummoner";
	static final int MARK_OF_SUMMONER_ID = 3336;
	static final int LETOLIZARDMAN_AMULET_ID = 3337;
	static final int SAC_OF_REDSPORES_ID = 3338;
	static final int KARULBUGBEAR_TOTEM_ID = 3339;
	static final int SHARDS_OF_MANASHEN_ID = 3340;
	static final int BREKAORC_TOTEM_ID = 3341;
	static final int CRIMSON_BLOODSTONE_ID = 3342;
	static final int TALONS_OF_TYRANT_ID = 3343;
	static final int WINGS_OF_DRONEANT_ID = 3344;
	static final int TUSK_OF_WINDSUS_ID = 3345;
	static final int FANGS_OF_WYRM_ID = 3346;
	static final int LARS_LIST1_ID = 3347;
	static final int LARS_LIST2_ID = 3348;
	static final int LARS_LIST3_ID = 3349;
	static final int LARS_LIST4_ID = 3350;
	static final int LARS_LIST5_ID = 3351;
	static final int GALATEAS_LETTER_ID = 3352;
	static final int BEGINNERS_ARCANA_ID = 3353;
	static final int ALMORS_ARCANA_ID = 3354;
	static final int CAMONIELL_ARCANA_ID = 3355;
	static final int BELTHUS_ARCANA_ID = 3356;
	static final int BASILLIA_ARCANA_ID = 3357;
	static final int CELESTIEL_ARCANA_ID = 3358;
	static final int BRYNTHEA_ARCANA_ID = 3359;
	static final int CRYSTAL_OF_PROGRESS1_ID = 3360;
	static final int CRYSTAL_OF_INPROGRESS1_ID = 3361;
	static final int CRYSTAL_OF_FOUL1_ID = 3362;
	static final int CRYSTAL_OF_DEFEAT1_ID = 3363;
	static final int CRYSTAL_OF_VICTORY1_ID = 3364;
	static final int CRYSTAL_OF_PROGRESS2_ID = 3365;
	static final int CRYSTAL_OF_INPROGRESS2_ID = 3366;
	static final int CRYSTAL_OF_FOUL2_ID = 3367;
	static final int CRYSTAL_OF_DEFEAT2_ID = 3368;
	static final int CRYSTAL_OF_VICTORY2_ID = 3369;
	static final int CRYSTAL_OF_PROGRESS3_ID = 3370;
	static final int CRYSTAL_OF_INPROGRESS3_ID = 3371;
	static final int CRYSTAL_OF_FOUL3_ID = 3372;
	static final int CRYSTAL_OF_DEFEAT3_ID = 3373;
	static final int CRYSTAL_OF_VICTORY3_ID = 3374;
	static final int CRYSTAL_OF_PROGRESS4_ID = 3375;
	static final int CRYSTAL_OF_INPROGRESS4_ID = 3376;
	static final int CRYSTAL_OF_FOUL4_ID = 3377;
	static final int CRYSTAL_OF_DEFEAT4_ID = 3378;
	static final int CRYSTAL_OF_VICTORY4_ID = 3379;
	static final int CRYSTAL_OF_PROGRESS5_ID = 3380;
	static final int CRYSTAL_OF_INPROGRESS5_ID = 3381;
	static final int CRYSTAL_OF_FOUL5_ID = 3382;
	static final int CRYSTAL_OF_DEFEAT5_ID = 3383;
	static final int CRYSTAL_OF_VICTORY5_ID = 3384;
	static final int CRYSTAL_OF_PROGRESS6_ID = 3385;
	static final int CRYSTAL_OF_INPROGRESS6_ID = 3386;
	static final int CRYSTAL_OF_FOUL6_ID = 3387;
	static final int CRYSTAL_OF_DEFEAT6_ID = 3388;
	static final int CRYSTAL_OF_VICTORY6_ID = 3389;
	static final int[] npc =
	{
		30063,
		30634,
		30635,
		30636,
		30637,
		30638,
		30639,
		30640
	};
	static int Lara = npc[0];
	static int Galatea = npc[1];
	static int Almors = npc[2];
	static int Camoniell = npc[3];
	static int Belthus = npc[4];
	static int Basilla = npc[5];
	static int Celestiel = npc[6];
	static int Brynthea = npc[7];
	static int[][] SUMMONERS =
	{
		{
			30635,
			ALMORS_ARCANA_ID,
			CRYSTAL_OF_VICTORY1_ID
		}, // Almors
		
		{
			30636,
			CAMONIELL_ARCANA_ID,
			CRYSTAL_OF_VICTORY2_ID
		},// Camoniell
		
		{
			30637,
			BELTHUS_ARCANA_ID,
			CRYSTAL_OF_VICTORY3_ID
		}, // Belthus
		
		{
			30638,
			BASILLIA_ARCANA_ID,
			CRYSTAL_OF_VICTORY4_ID
		}, // Basilla
		
		{
			30639,
			CELESTIEL_ARCANA_ID,
			CRYSTAL_OF_VICTORY5_ID
		},// Celestiel
		
		{
			30640,
			BRYNTHEA_ARCANA_ID,
			CRYSTAL_OF_VICTORY6_ID
		}
	// Brynthea
	};
	static final HashMap<Integer, String> NAMES = new HashMap<>();
	
	static
	{
		NAMES.put(30635, "Almors");
		NAMES.put(30636, "Camoniell");
		NAMES.put(30637, "Belthus");
		NAMES.put(30638, "Basilla");
		NAMES.put(30639, "Celestiel");
		NAMES.put(30640, "Brynthea");
	}
	static final HashMap<Integer, Integer[]> DROPLIST_LARA = new HashMap<>();
	
	static
	{
		DROPLIST_LARA.put(20555, new Integer[]
		{
			1,
			80,
			SAC_OF_REDSPORES_ID
		});
		DROPLIST_LARA.put(20557, new Integer[]
		{
			1,
			25,
			LETOLIZARDMAN_AMULET_ID
		});
		DROPLIST_LARA.put(20558, new Integer[]
		{
			1,
			25,
			LETOLIZARDMAN_AMULET_ID
		});
		DROPLIST_LARA.put(20559, new Integer[]
		{
			1,
			25,
			LETOLIZARDMAN_AMULET_ID
		});
		DROPLIST_LARA.put(20580, new Integer[]
		{
			1,
			50,
			LETOLIZARDMAN_AMULET_ID
		});
		DROPLIST_LARA.put(20581, new Integer[]
		{
			1,
			75,
			LETOLIZARDMAN_AMULET_ID
		});
		DROPLIST_LARA.put(20582, new Integer[]
		{
			1,
			75,
			LETOLIZARDMAN_AMULET_ID
		});
		DROPLIST_LARA.put(20600, new Integer[]
		{
			2,
			80,
			KARULBUGBEAR_TOTEM_ID
		});
		DROPLIST_LARA.put(20563, new Integer[]
		{
			2,
			80,
			SHARDS_OF_MANASHEN_ID
		});
		DROPLIST_LARA.put(20552, new Integer[]
		{
			3,
			60,
			CRIMSON_BLOODSTONE_ID
		});
		DROPLIST_LARA.put(20267, new Integer[]
		{
			3,
			25,
			BREKAORC_TOTEM_ID
		});
		DROPLIST_LARA.put(20268, new Integer[]
		{
			3,
			25,
			BREKAORC_TOTEM_ID
		});
		DROPLIST_LARA.put(20271, new Integer[]
		{
			3,
			25,
			BREKAORC_TOTEM_ID
		});
		DROPLIST_LARA.put(20269, new Integer[]
		{
			3,
			50,
			BREKAORC_TOTEM_ID
		});
		DROPLIST_LARA.put(20270, new Integer[]
		{
			3,
			50,
			BREKAORC_TOTEM_ID
		});
		DROPLIST_LARA.put(20553, new Integer[]
		{
			4,
			70,
			TUSK_OF_WINDSUS_ID
		});
		DROPLIST_LARA.put(20192, new Integer[]
		{
			4,
			50,
			TALONS_OF_TYRANT_ID
		});
		DROPLIST_LARA.put(20193, new Integer[]
		{
			4,
			50,
			TALONS_OF_TYRANT_ID
		});
		DROPLIST_LARA.put(20089, new Integer[]
		{
			5,
			30,
			WINGS_OF_DRONEANT_ID
		});
		DROPLIST_LARA.put(20090, new Integer[]
		{
			5,
			60,
			WINGS_OF_DRONEANT_ID
		});
		DROPLIST_LARA.put(20176, new Integer[]
		{
			5,
			50,
			FANGS_OF_WYRM_ID
		});
	}
	static String[] STATS =
	{
		"cond",
		"step",
		"Lara_Part",
		"Arcanas",
		"Belthus",
		"Brynthea",
		"Celestiel",
		"Camoniell",
		"Basilla",
		"Almors"
	};
	static int[][] LISTS =
	{
		{}, // zero element filler
		
		{
			LARS_LIST1_ID,
			SAC_OF_REDSPORES_ID,
			LETOLIZARDMAN_AMULET_ID
		}, // List
		
		{
			LARS_LIST2_ID,
			KARULBUGBEAR_TOTEM_ID,
			SHARDS_OF_MANASHEN_ID
		}, // List
		
		{
			LARS_LIST3_ID,
			CRIMSON_BLOODSTONE_ID,
			BREKAORC_TOTEM_ID
		}, // List
		
		{
			LARS_LIST4_ID,
			TUSK_OF_WINDSUS_ID,
			TALONS_OF_TYRANT_ID
		}, // List
		
		{
			LARS_LIST5_ID,
			WINGS_OF_DRONEANT_ID,
			FANGS_OF_WYRM_ID
		}
	// List 5
	};
	
	public Q230_TestOfSummoner(int questId, String name, String descr)
	{
		super(questId, name, descr);
		addStartNpc(Galatea);
		addTalkId(npc);
		for (int mobId : DROPLIST_LARA.keySet())
		{
			addKillId(mobId);
		}
		for (int mobId : DROPLIST_SUMMON.keySet())
		{
			addKillId(mobId);
			addAttackId(mobId);
		}
		for (int i = 3337; i <= 3389; i++)
		{
			questItemIds = new int[]
			{
				i
			};
		}
	}
	
	@Override
	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	{
		String htmltext = event;
		QuestState st = player.getQuestState(qn);
		if (event.equalsIgnoreCase("30634-08.htm"))
		{ // start part for Galatea
			for (String var : STATS)
			{
				if (var.equalsIgnoreCase("Arcanas") || var.equalsIgnoreCase("Lara_Part"))
				{
					continue;
				}
				st.set(var, "1");
			}
			st.setState(STATE_STARTED);
			st.playSound(QuestState.SOUND_ACCEPT);
			st.giveItems(7562, 64);
		}
		else if (event.equalsIgnoreCase("30634-07.htm"))
		{
			st.giveItems(GALATEAS_LETTER_ID, 1);
		}
		else if (event.equalsIgnoreCase("30063-02.htm"))
		{ // Lara first time to
			int random = Rnd.get(5) + 1;
			st.giveItems(LISTS[random][0], 1);
			st.takeItems(GALATEAS_LETTER_ID, 1);
			st.set("Lara_Part", "" + random);
			st.set("step", "2");
			st.set("cond", "2");
		}
		else if (event.equalsIgnoreCase("30063-04.htm"))
		{ // Lara later to
			int random = Rnd.get(5) + 1;
			st.giveItems(LISTS[random][0], 1);
			st.set("Lara_Part", "" + random);
		}
		else if (event.equalsIgnoreCase("30635-02.htm"))
		{
			if (st.getQuestItemsCount(BEGINNERS_ARCANA_ID) > 0)
			{
				htmltext = "30635-03.htm";
				st.set("Almors", "2");
			}
		}
		else if (event.equalsIgnoreCase("30635-04.htm"))
		{
			st.giveItems(CRYSTAL_OF_PROGRESS1_ID, 1);
			st.takeItems(CRYSTAL_OF_FOUL1_ID, -1);
			st.takeItems(CRYSTAL_OF_DEFEAT1_ID, -1);
			st.takeItems(BEGINNERS_ARCANA_ID, 1);
		}
		else if (event.equalsIgnoreCase("30636-02.htm"))
		{ // Camoniell's Part
			if (st.getQuestItemsCount(BEGINNERS_ARCANA_ID) > 0)
			{
				htmltext = "30636-03.htm";
				st.set("Camoniell", "2");
			}
		}
		else if (event.equalsIgnoreCase("30636-04.htm"))
		{
			st.giveItems(CRYSTAL_OF_PROGRESS2_ID, 1);
			st.takeItems(CRYSTAL_OF_FOUL2_ID, -1);
			st.takeItems(CRYSTAL_OF_DEFEAT2_ID, -1);
			st.takeItems(BEGINNERS_ARCANA_ID, 1);
		}
		else if (event.equalsIgnoreCase("30637-02.htm"))
		{ // Belthus' Part
			if (st.getQuestItemsCount(BEGINNERS_ARCANA_ID) > 0)
			{
				htmltext = "30637-03.htm";
				st.set("Belthus", "2");
			}
		}
		else if (event.equalsIgnoreCase("30637-04.htm"))
		{
			st.giveItems(CRYSTAL_OF_PROGRESS3_ID, 1);
			st.takeItems(CRYSTAL_OF_FOUL3_ID, -1);
			st.takeItems(CRYSTAL_OF_DEFEAT3_ID, -1);
			st.takeItems(BEGINNERS_ARCANA_ID, 1);
		}
		else if (event.equalsIgnoreCase("30638-02.htm"))
		{ // Basilla's Part
			if (st.getQuestItemsCount(BEGINNERS_ARCANA_ID) > 0)
			{
				htmltext = "30638-03.htm";
				st.set("Basilla", "2");
			}
		}
		else if (event.equalsIgnoreCase("30638-04.htm"))
		{
			st.giveItems(CRYSTAL_OF_PROGRESS4_ID, 1);
			st.takeItems(CRYSTAL_OF_FOUL4_ID, -1);
			st.takeItems(CRYSTAL_OF_DEFEAT4_ID, -1);
			st.takeItems(BEGINNERS_ARCANA_ID, 1);
		}
		else if (event.equalsIgnoreCase("30639-02.htm"))
		{ // Celestiel's Part
			if (st.getQuestItemsCount(BEGINNERS_ARCANA_ID) > 0)
			{
				htmltext = "30639-03.htm";
				st.set("Celestiel", "2");
			}
		}
		else if (event.equalsIgnoreCase("30639-04.htm"))
		{
			st.giveItems(CRYSTAL_OF_PROGRESS5_ID, 1);
			st.takeItems(CRYSTAL_OF_FOUL5_ID, -1);
			st.takeItems(CRYSTAL_OF_DEFEAT5_ID, -1);
			st.takeItems(BEGINNERS_ARCANA_ID, 1);
		}
		else if (event.equalsIgnoreCase("30640-02.htm"))
		{ // Brynthea's Part
			if (st.getQuestItemsCount(BEGINNERS_ARCANA_ID) > 0)
			{
				htmltext = "30640-03.htm";
				st.set("Brynthea", "2");
			}
		}
		else if (event.equalsIgnoreCase("30640-04.htm"))
		{
			st.giveItems(CRYSTAL_OF_PROGRESS6_ID, 1);
			st.takeItems(CRYSTAL_OF_FOUL6_ID, -1);
			st.takeItems(CRYSTAL_OF_DEFEAT6_ID, -1);
			st.takeItems(BEGINNERS_ARCANA_ID, 1);
		}
		return htmltext;
	}
	
	@Override
	public String onTalk(L2Npc npc, L2PcInstance player)
	{
		QuestState st = player.getQuestState(qn);
		if (st.getQuestItemsCount(MARK_OF_SUMMONER_ID) > 0)
		{
			st.exitQuest(true);
			return getAlreadyCompletedMsg();
		}
		String htmltext = getNoQuestMsg();
		int npcId = npc.getNpcId();
		int id = st.getState();
		if ((id == STATE_CREATED) && (npcId == 30634))
		{ // start part, Galatea
			for (String var : STATS)
			{
				st.set(var, "0");
			}
			if ((st.getPlayer().getClassId() == ClassId.wizard) || (st.getPlayer().getClassId() == ClassId.elvenWizard) || (st.getPlayer().getClassId() == ClassId.darkWizard))
			{
				if (st.getPlayer().getLevel() > 38) // conditions are ok, lets
				{
					htmltext = "30634-03.htm";
				}
				else
				{
					htmltext = "30634-02.htm"; // too young.. not now
					st.exitQuest(true);
				}
			}
			else
			{ // wrong class.. never
				htmltext = "30634-01.htm";
				st.exitQuest(true);
			}
		}
		else if (id == STATE_STARTED)
		{
			int LaraPart = st.getInt("Lara_Part");
			int Arcanas = st.getInt("Arcanas");
			int step = st.getInt("step"); // stats as short vars if( the player
			if (npcId == 30634)
			{ // Start&&End Npc Galatea related stuff
				if (step == 1) // step 1 means just started
				{
					htmltext = "30634-09.htm";
				}
				else if (step == 2)
				{ // step 2 means already talkd with lara
					if (Arcanas == 6)
					{ // finished all battles... the player is
						htmltext = "30634-12.htm";
						st.playSound(QuestState.SOUND_FINISH);
						st.takeItems(LARS_LIST1_ID, -1);
						st.takeItems(LARS_LIST2_ID, -1);
						st.takeItems(LARS_LIST3_ID, -1);
						st.takeItems(LARS_LIST4_ID, -1);
						st.takeItems(LARS_LIST5_ID, -1);
						st.takeItems(ALMORS_ARCANA_ID, -1);
						st.takeItems(BASILLIA_ARCANA_ID, -1);
						st.takeItems(CAMONIELL_ARCANA_ID, -1);
						st.takeItems(CELESTIEL_ARCANA_ID, -1);
						st.takeItems(BELTHUS_ARCANA_ID, -1);
						st.takeItems(BRYNTHEA_ARCANA_ID, -1);
						st.giveItems(MARK_OF_SUMMONER_ID, 1);
						st.getPlayer().addExpAndSp(148409, 30000);
						st.playSound(QuestState.SOUND_FINISH);
						st.unset("cond");
						st.exitQuest(true);
					}
				}
				else
				{
					htmltext = "30634-10.htm";
				}
			}
			else if (npcId == Lara)
			{ // anything realated to Lara below
				if (step == 1) // first talk to lara
				{
					htmltext = "30063-01.htm";
				}
				else if (LaraPart == 0) // if( you havent a part taken, give one
				{
					htmltext = "30063-03.htm";
				}
				else
				{
					long ItemCount1 = st.getQuestItemsCount(LISTS[LaraPart][1]);
					long ItemCount2 = st.getQuestItemsCount(LISTS[LaraPart][2]);
					if ((ItemCount1 < 30) || (ItemCount2 < 30)) // if( you have not
					{
						htmltext = "30063-05.htm";
					}
					else if ((ItemCount1 > 29) && (ItemCount2 > 29))
					{// if( you
						htmltext = "30063-06.htm";
						st.giveItems(BEGINNERS_ARCANA_ID, 2);
						st.takeItems(LISTS[LaraPart][0], 1);
						st.takeItems(LISTS[LaraPart][1], -1);
						st.takeItems(LISTS[LaraPart][2], -1);
						st.set("cond", "3");
						st.set("Lara_Part", "0");
					}
				}
			}
			else
			{
				for (int[] i : SUMMONERS)
				{
					if (i[0] == npcId)
					{
						int SummonerStat = st.getInt(NAMES.get(i[0]));
						if (step > 1)
						{
							if (SummonerStat == 1) // default, just able to
							{
								htmltext = npcId + "-01.htm";
							}
							else if (SummonerStat == 2) // ready to fight...
							{
								htmltext = npcId + "-08.htm";
							}
							else if (SummonerStat == 3)
							{ // in battle...
								notifyDeath(npc, st.getPlayer(), st.getPlayer());
								notifyDeath(npc, st.getPlayer().getPet(), st.getPlayer());
								htmltext = npcId + "-09.htm";
							}
							else if (SummonerStat == 4) // haha... your summon
							{
								htmltext = npcId + "-05.htm";
							}
							else if (SummonerStat == 5) // hey.. shit cheater..
							{
								htmltext = npcId + "-06.htm";
							}
							else if (SummonerStat == 6)
							{ // damn.. you won the
								htmltext = npcId + "-07.htm";
								st.takeItems(SUMMONERS[npcId - 30635][2], -1); // take
								st.giveItems(SUMMONERS[npcId - 30635][1], 1);// give arcana
								if ((st.getQuestItemsCount(3354) + st.getQuestItemsCount(3355) + st.getQuestItemsCount(3356) + st.getQuestItemsCount(3357) + st.getQuestItemsCount(3358) + st.getQuestItemsCount(3359)) >= 6)
								{
									st.set("cond", "4");
								}
								st.set(NAMES.get(i[0]), "7"); // set 7, this
								st.set("Arcanas", "" + Arcanas + 1);
							} // set arcana stat +1, if( its 6... quest is
							else if (SummonerStat == 7) // you already won the
							{
								htmltext = npcId + "-10.htm";
							}
						}
					}
				}
			}
		}
		return htmltext;
	}
	
	static final HashMap<Integer, Integer[]> DROPLIST_SUMMON = new HashMap<>();
	
	static
	{
		DROPLIST_SUMMON.put(27102, new Integer[]
		{
			CRYSTAL_OF_PROGRESS1_ID,
			CRYSTAL_OF_INPROGRESS1_ID,
			CRYSTAL_OF_FOUL1_ID,
			CRYSTAL_OF_DEFEAT1_ID,
			CRYSTAL_OF_VICTORY1_ID
		}); // Pako the
		DROPLIST_SUMMON.put(27103, new Integer[]
		{
			CRYSTAL_OF_PROGRESS2_ID,
			CRYSTAL_OF_INPROGRESS2_ID,
			CRYSTAL_OF_FOUL2_ID,
			CRYSTAL_OF_DEFEAT2_ID,
			CRYSTAL_OF_VICTORY2_ID
		}); // Mimi the
		DROPLIST_SUMMON.put(27104, new Integer[]
		{
			CRYSTAL_OF_PROGRESS3_ID,
			CRYSTAL_OF_INPROGRESS3_ID,
			CRYSTAL_OF_FOUL3_ID,
			CRYSTAL_OF_DEFEAT3_ID,
			CRYSTAL_OF_VICTORY3_ID
		}); // Shadow
		DROPLIST_SUMMON.put(27105, new Integer[]
		{
			CRYSTAL_OF_PROGRESS4_ID,
			CRYSTAL_OF_INPROGRESS4_ID,
			CRYSTAL_OF_FOUL4_ID,
			CRYSTAL_OF_DEFEAT4_ID,
			CRYSTAL_OF_VICTORY4_ID
		}); // Unicorn
		DROPLIST_SUMMON.put(27106, new Integer[]
		{
			CRYSTAL_OF_PROGRESS5_ID,
			CRYSTAL_OF_INPROGRESS5_ID,
			CRYSTAL_OF_FOUL5_ID,
			CRYSTAL_OF_DEFEAT5_ID,
			CRYSTAL_OF_VICTORY5_ID
		}); // Unicorn
		DROPLIST_SUMMON.put(27107, new Integer[]
		{
			CRYSTAL_OF_PROGRESS6_ID,
			CRYSTAL_OF_INPROGRESS6_ID,
			CRYSTAL_OF_FOUL6_ID,
			CRYSTAL_OF_DEFEAT6_ID,
			CRYSTAL_OF_VICTORY6_ID
		}); // Silhoutte
	}
	
	static
	{
		NAMES.put(27102, "Almors");
		NAMES.put(27103, "Camoniell");
		NAMES.put(27104, "Belthus");
		NAMES.put(27105, "Basilla");
		NAMES.put(27106, "Celestiel");
		NAMES.put(27107, "Brynthea");
	}
	
	@Override
	public String onDeath(L2Character killer, L2Character victim, L2PcInstance player)
	{ // if players summon dies, the crystal of defeat is
		QuestState st = checkPlayerState(player, (L2Npc) killer, STATE_STARTED);
		int npcId = ((L2Npc) killer).getNpcId();
		if ((victim == st.getPlayer()) || (victim == st.getPlayer().getPet()))
		{
			if ((npcId >= 27102) && (npcId <= 27107))
			{
				String[] VARS =
				{
					"Almors",
					"Camoniell",
					"Belthus",
					"Basilla",
					"Celestiel",
					"Brynthea"
				};
				String var = VARS[npcId - 27102];
				Integer[] i = DROPLIST_SUMMON.get(npcId);
				int defeat = i[3];
				if (st.getInt(var) == 3)
				{
					st.set(var, "4");
					st.giveItems(defeat, 1);
				}
			}
		}
		return null;
	}
	
	@Override
	public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isPet)
	{ // on the first
		int npcId = npc.getNpcId();
		QuestState st = checkPlayerState(player, npc, STATE_STARTED);
		if ((npcId >= 27102) && (npcId <= 27107))
		{
			String[] VARS =
			{
				"Almors",
				"Camoniell",
				"Belthus",
				"Basilla",
				"Celestiel",
				"Brynthea"
			};
			String var = VARS[npcId - 27102];
			Integer[] i = DROPLIST_SUMMON.get(npcId);
			int start = i[0];
			int progress = i[1];
			if (st.getInt(var) == 2)
			{
				st.set(var, "3");
				st.giveItems(progress, 1);
				st.takeItems(start, 1);
				st.playSound(QuestState.SOUND_ITEMGET);
			}
		}
		return null;
	}
	
	@Override
	public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
	{
		QuestState st = checkPlayerState(player, npc, STATE_STARTED);
		if (st == null)
		{
			return null;
		}
		int npcId = npc.getNpcId(); // this part is just for laras parts
		if (DROPLIST_LARA.containsKey(npcId))
		{
			Integer[] i = DROPLIST_LARA.get(npcId);
			String var = "Lara_Part";
			int value = i[0];
			int chance = i[1];
			int item = i[2];
			long count = st.getQuestItemsCount(item);
			if ((st.getInt(var) == value) && (count < 30) && Rnd.chance(chance))
			{
				st.giveItems(item, 1);
				if (count == 29)
				{
					st.playSound(QuestState.SOUND_MIDDLE);
				}
				else
				{
					st.playSound(QuestState.SOUND_ITEMGET);
				}
			}
		}
		else if (DROPLIST_SUMMON.containsKey(npcId))
		{ // if a summon dies
			String[] VARS =
			{
				"Almors",
				"Camoniell",
				"Belthus",
				"Basilla",
				"Celestiel",
				"Brynthea"
			};
			String var = VARS[npcId - 27102];
			Integer[] i = DROPLIST_SUMMON.get(npcId);
			int progress = i[1];
			int foul = i[2];
			int victory = i[4];
			if (st.getInt(var) == 3)
			{
				boolean isFoul = st.getQuestItemsCount(foul) == 0;
				int isName = 1; // first entry in the droplist is a name (string).  Skip it.
				for (Integer item : DROPLIST_SUMMON.get(npcId))
				{ // take all crystal of this summoner away from the player
					if (isName != 1)
					{
						st.takeItems(item, -1);
					}
					isName = 0;
				}
				st.takeItems(progress, -1);
				if (isFoul)
				{
					st.set(var, "6");
					st.giveItems(victory, 1); // if he wons without cheating, set stat won and give victory crystal
					st.playSound(QuestState.SOUND_MIDDLE);
				}
				else
				{
					st.set(var, "5"); // if the player cheats, give foul crystal and set stat to cheat
				}
			}
		}
		return null;
	}
	
	public static void onLoad()
	{
		new Q230_TestOfSummoner(230, qn, "Test Of Summoner");
	}
}
